package com.springbootsecuritydemo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.springbootsecuritydemo.entity.MenuEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Daft_V
 * @date 2022/4/27 11:17
 */
@Mapper
public interface MenuMapper extends BaseMapper<MenuEntity> {

    /**
     * 根据用户id获取权限列表
     *
     * @param id 用户id
     * @return List
     */
    @Select("select distinct permission from menu where id IN (SELECT menu_id from role_menu where role_id IN (SELECT b.role_id FROM user a, user_role b where a.id = b.user_id and a.id=#{id}))")
    List<String> componentListByUserId(@Param("id") Long id);
}
